package com.zhf.JDBC02;

import com.zhf.utils.JDBCUtils;

import java.sql.*;

/**
 * @Author: ZhaoHuanfeng
 * @Date: 2020/9/23 21:37
 */
public class TestDQL {

    public static void main(String[] args) throws SQLException {
        //获取连接
        Connection connection = JDBCUtils.getConnection();

        //获取执行对象
        Statement statement = connection.createStatement();

        //执行SQL并获取结果
        String sql="select * from jdbc_user where username='赵桓锋';";
        ResultSet resultSet = statement.executeQuery(sql);

        //处理获取到的结果
        while (resultSet.next()){
            int id = resultSet.getInt("id");
            String username = resultSet.getString("username");
            String password = resultSet.getString("password");
            Date birthday = resultSet.getDate("birthday");
            System.out.println(id+"--"+username+"--"+password+"--"+birthday);
        }

        //关闭流对象
        JDBCUtils.close(connection,statement,resultSet);

    }
}
